package com.cmd.driver;


import com.alibaba.fastjson.JSONObject;
import com.mgr.UserOrderMgr;
import com.player.User;
import com.qy.bean.OrderInfo;
import com.qy.util.StaticData;
import com.util.AbstractCommand;
import com.util.PBMessage;

/**
 * 
 * 订单不能联系，
 * 还车用户点击送往公司指定地址
 * 
 * @author zwl 2018年2月1日
 */
public class OrderNotContactCMD extends AbstractCommand {

    @Override
    public void execute(User user, PBMessage packet) throws Exception {
	JSONObject reJs = new JSONObject();
	reJs.put(StaticData.reKey.cmd.getKey(),packet.getCode());
	JSONObject param = packet.getMessage();
	if (!param.containsKey("orderId")) {
	    reJs.put(StaticData.reKey.code.getKey(),StaticData.codeType.param_error.getType());
	    user.sendPacket(reJs);
	    return;
	}
	// 订单号
	int orderId = param.getInteger("orderId");
	OrderInfo info = UserOrderMgr.getOrderInfo(orderId);
	if (info == null
		||info.getOrderStatus() != StaticData.OrderStatus.ARRIVE_COUNT_DOWN.getType()) {
	    reJs.put(StaticData.reKey.code.getKey(),StaticData.codeType.ORDER_not_exist.getType());
	    user.sendPacket(reJs);
	    return;
	}
	/*
	 * 修改订单状态
	 */
	info.setOrderStatus(StaticData.OrderStatus.COUNT_DOWN_OVER.getType());
	UserOrderMgr.update(info);
	
	reJs.put(StaticData.reKey.code.getKey(),StaticData.codeType.ok.getType());
	reJs.put(StaticData.reKey.cmd.getKey(),packet.getCode());
	user.sendPacket(reJs);
	return;
    }

}
